//
//  TabBarHeaderView.m
//  zhijian
//
//  Created by yiban on 2019/1/22.
//  Copyright © 2019 lcb. All rights reserved.
//

#import "TabBarHeaderView.h"

@interface TabBarHeaderView()
{
    
}
@property(nonatomic,assign)BOOL isStop;
@property(nonatomic,strong) NSArray*segItems;
@end

@implementation TabBarHeaderView

@synthesize delegate=_delegate;
@synthesize isStop=_isStop;
@synthesize segControl=_segControl;
@synthesize segItems=_segItems;
-(instancetype)initWithFrame:(CGRect)frame item:(NSArray*)items{
    if (self = [super initWithFrame:frame]) {
        self.segItems =items;
        [self makeSearchView:frame];
    }
    
    return self;
}

-(UISegmentedControl*)segControl
{
    if (!_segControl) {
        _segControl= [[UISegmentedControl alloc] initWithItems:self.segItems];
        [_segControl setTintColor:[UIColor clearColor]];
        //文字设置
        NSMutableDictionary *attDic = [NSMutableDictionary dictionary];
        attDic[NSFontAttributeName] = [UIFont systemFontOfSize:18] ;
        attDic[NSForegroundColorAttributeName] = UIColorOfHex(0xffffff);
        
        NSMutableDictionary *attSelDic = [NSMutableDictionary dictionary];
        attSelDic[NSFontAttributeName] = [UIFont boldSystemFontOfSize:18];
        attSelDic[NSForegroundColorAttributeName] = UIColorOfHex(0xffffff);
        
        [_segControl setTitleTextAttributes:attDic forState:UIControlStateNormal];
        [_segControl setTitleTextAttributes:attSelDic forState:UIControlStateSelected];
        
        //事件
        _segControl.selectedSegmentIndex = 0;
        [_segControl addTarget:self action:@selector(titleViewChange:) forControlEvents:UIControlEventValueChanged];
        [self addSubview:_segControl];
    }
    return _segControl;
}
- (void)makeSearchView:(CGRect) frame {
    self.segControl.frame = CGRectMake((SCREEN_WIDTH - SCREEN_WIDTH/2)/2, 0, SCREEN_WIDTH/2, 44);
}
- (void)titleViewChange:(UISegmentedControl *)segment {
    if ([self.delegate respondsToSelector:@selector(searchClickWithButton:)]) {
        [self.delegate searchClickWithButton:segment.selectedSegmentIndex];
    }
    
}

@end
